<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品评论列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>商品名称：</label>
                                <input type="text" name="goodsName"/>
                            </li>
                            <li>
                                <label>会员昵称：</label>
                                <input type="text" name="loginName"/>
                            </li>
                            <li>
                                <label>是否回复：</label>
					             <select name="replyStatus"  class="form-control" th:with="type=${@dict.getType('shop_yes_no')}">
	                                <option value="">全部</option>
	                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                            </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('goods:evaluate:edit')}]];
        var removeFlag = [[${@permission.hasPermi('goods:evaluate:remove')}]];
        var prefix = ctx + "shop/goods/evaluate";
        var states = [[${@dict.getType('sys_show_hide')}]];
        var datas = [[${@dict.getType('shop_yes_no')}]];
        var evaluates = [[${@dict.getType('shop_evaluate_type')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "商品评价",
                columns: [
                {
                    field: 'image',
                    title: '图片',
                    align: 'center',
                   	formatter: function (value, row, index) {
                   		 if(value==null||value==''){
                   			 return '';
                   		 }
                         return "<img src='"+ value+ "' style='width:30px;height:30px;' target='_blank' title='点击查看详情' onclick='detailGoods(\""+ row.goodsId +"\")'></img>";
  					 }
                },
                {
                    field: 'goodsName',
                    title: '商品名称',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	return $.table.tooltip(value);
                    }
                },
                {
                    field: 'loginName',
                    title: '会员',
                    align: 'center'
                },
                {
                    field: 'evaluateType',
                    title: '评价等级',
                    align: 'center',
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(evaluates, value);
                    }
                },
                {
                    field: 'star',
                    title: '综合评分',
                    align: 'center'
                },
                {
                    field: 'createTime',
                    title: '评价时间',
                    align: 'center'
                },
                {
                    field: 'content',
                    title: '评价内容',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	return $.table.tooltip(value);
                    }
                },
                {
                    field: 'replyContent',
                    title: '回复内容',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	return $.table.tooltip(value);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
		        	title: '显示状态',
		        	align: 'center',
		        	formatter: function (value, row, index) {
		        		return statusTools(row);
		        	}
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.evaluateId + '\')"><i class="fa fa-search"></i>详情</a> ');
                        if (row.replyStatus == 1) {
                          actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="reply(\'' + row.evaluateId + '\')"><i class="fa fa-reply"></i>回复</a> ');
                        }                        
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.evaluateId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        
        function detailGoods(goodsId){
                var options = {
                    url: ctx+"shop/goods/detail/"+goodsId,
                    title: "商品详细",
                    width: 1100,
                    height: 700,
                    skin: 'layui-layer-gray', 
                    btn: ['关闭'],
                    yes: function (index, layero) {
                        $.modal.close(index);
                    }
                };
                $.modal.openOptions(options);	
		}
        	
		/** 预览轮播图片 */
	    function imagePreview(url){
			layer.photos({ photos: { "data": [{ "src": url}]}});
		}
		
		
		//回复内容
	    function reply(evaluateId){
		  	 layer.prompt({title: '回复内容', formType: 2}, function(itemName, index){
		    	    $.ajax({
						type : "post",
						url : prefix + "/replay",
						data : {evaluateId:evaluateId,replyContent:itemName},
						success : function(result) {
							if (result.code == web_status.SUCCESS) {
								  layer.close(index);
								$.table.search()
							} else {
								$.modal.alertError(result.msg);
							}
						},
						error : function(error) {
							$.modal.alertWarning(error);
						}
					});
		  	   });
		} 
		
		/* 状态显示 */
		function statusTools(row) {
		    if (row.status == 1) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.evaluateId + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.evaluateId + '\')"></i> ';
    		}
		}
		
		/* 隐藏 */
		function disable(evaluateId) {
			$.modal.confirm("确认前台隐藏该评论吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "evaluateId": evaluateId, "status": 1 });
		    })
		}

		/* 显示 */
		function enable(evaluateId) {
			$.modal.confirm("确认前台显示该评论吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "evaluateId": evaluateId, "status": 0 });
		    })
		}
    </script>
</body>
</html>